"""online_class URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView
# 使用内置类来返回html页面
from django.views.decorators.csrf import csrf_exempt
#  去除token验证，对某一个view
from django.views.static import serve

import xadmin

from apps.users.views import LoginView, LogoutView, SendSmsView, DynamicLoginView, RegisterView
from apps.organizations.views import OrgView
from online_class.settings import MEDIA_ROOT
from apps.operations.views import IndexView
urlpatterns = [
    # path('admin/', admin.site.urls),
    path('xadmin/', xadmin.site.urls),
    path('', IndexView.as_view(), name='index'),
    # 返回某个html页面
    # 简单返回页面不能做查验
    # path('login/', TemplateView.as_view(template_name="login.html"), name="login")
    # # 配置别名 前端页面使用href="{% url "login" %}跳转
    path('login/', LoginView.as_view(), name="login"),
    path('d_login/', DynamicLoginView.as_view(), name="d_login"),
    path('loginout/', LogoutView.as_view(), name="logout"),
    path('register/', RegisterView.as_view(), name="register"),
    url(r'^captcha/', include('captcha.urls')),
    url(r'^send_sms/', csrf_exempt(SendSmsView.as_view()), name="send_sms"),
    # 配置文件的访问URL
    url(r'media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
    # url(r'static/(?P<path>.*)$', serve, {"document_root": STATIC_ROOT}),
    # 机构相关页面
    # url(r'^org_list/', OrgView.as_view(), name='org_list'),
    url(r'^org/', include(('apps.organizations.urls', "organizations"), namespace="org")),
    # 用户相关操作
    url(r'^op/', include(('apps.operations.urls', "operations"), namespace="op")),
    # 课程相关
    url(r'^course/', include(('apps.courses.urls', "courses"), namespace="course")),
    # 个人中心
    url(r'^users/', include(('apps.users.urls', "users"), namespace="users")),

]

# 1. CBV(class base view) 有利于代码复用
# 2. FBV(function base view)

# 编写一个view的几个步骤
"""
1.view代码
2. 配置url
3. 修改html页面中的相关配置
"""